//
//  RHChoiceDevTypeCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2025/1/3.
//

#import "RHChoiceDevTypeCell.h"
@interface RHChoiceDevTypeCell()

@property (nonatomic ,strong) UIView *bgView;

@property (nonatomic ,strong) QMUILabel *titleLab;

@property (nonatomic ,strong) UIView *line;

@property (nonatomic ,strong) UIImageView *selectImg;
@end
@implementation RHChoiceDevTypeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

- (void)setTypeModel:(RHDevTypeModel *)typeModel
{
    _typeModel = typeModel;
    self.titleLab.text = typeModel.plantType;
    if ([self.reuseIdentifier isEqualToString:@"RHChoiceDevTypeCell_left"]) {
        self.bgView.backgroundColor = typeModel.isSelected?kCOLOR_HEX(@"#ffffff"):kCOLOR_HEX(@"#F4F6F9");
        self.titleLab.textColor = typeModel.isSelected?kCOLOR_HEX(@"#05C79D"):kCOLOR_HEX(@"#303133");
    }else{
        self.selectImg.image = [UIImage imageNamed:typeModel.isSelected?@"choice_selected":@"choice_normal"];
    }
    
    
}

-(void)setupUI{
    kWeakSelf;
    _bgView = kView;
    _bgView.backgroundColor = CFTabViewBgColor;
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    _titleLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    _titleLab.numberOfLines = 0;
    [_bgView addSubview:_titleLab];
    
    
    _line = kView;
    _line.backgroundColor = kCOLOR_HEX(@"#EBEDF0");
    [_bgView addSubview:_line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.height.offset(1);
        make.bottom.mas_offset(0);
    }];
    
    
    
    if ([self.reuseIdentifier isEqualToString:@"RHChoiceDevTypeCell_left"]) {
        UIImageView *arrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow"]];
        [_bgView addSubview:arrow];
        [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(18);
            make.right.mas_offset(-15);
            make.centerY.mas_offset(0);
        }];
        
        [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.right.equalTo(arrow.mas_left).offset(-5);
            make.top.mas_offset(10);
            make.bottom.mas_offset(-10);
        }];
    }else{
        _bgView.backgroundColor = UIColor.whiteColor;
        _selectImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"choice_normal"]];
        [_bgView addSubview:_selectImg];
        [_selectImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(18);
            make.right.mas_offset(-15);
            make.centerY.mas_offset(0);
        }];
        
        [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.right.equalTo(weakSelf.selectImg.mas_left).offset(-5);
            make.top.mas_offset(10);
            make.bottom.mas_offset(-10);
        }];
    }
    
}
@end
